apiready = function() {
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service","../../pop"],function(V,$api,$,$app,service,$pop){
	var vm = {
		el: '.container',
	  	data: {
	    	list: '',
	    	address_id: ''
	  	},
	  	methods:{
	  		init: function(){
	  			this.getList()
	  		},
	  		getList: function(){
	  			var unionid = $api.getStorage("shop_unionid"), self = this;
		  		$app.ajax(service.addressGetList,{
		  			data: {
						values: {
							unionid: unionid
						}
					}
		  		},function(res){
		  			//console.log(JSON.stringify(res));
		  			if(res.code == 0){
		  				if(res.data.length > 0){
		  					self.list = res.data;
		  				}else{
		  					self.$refs.addressNull.style.display = "block";
		  				}
		  			}else{
		  				alert(res.message || res.msg);
		  			}
		  		});
	  		},
	  		//--选择地址
	  		orderAddressSelect: function(et){
	  			var address_id = et.currentTarget.dataset.addressid;
	  			var index = et.currentTarget.dataset.index;
	  			var data = this.list[+index];
	  			this.address_id = address_id;
	  			//--返回提交订单页面
	  			api.sendEvent({
					name:'addressSelect_',
					extra:{
						address_id: address_id,
						address: data
					}
				});
				$api.setTimeout(function(){
					api.closeWin();
				},300);
	  		},
	  		//--添加地址
	  		addressAdd: function(et){
	  			$app.openWin('buyAddressAdd',{
	  				type: 1
	  			});
	  		}
	  	},
	  	mounted:function() {
	  		var self = this;
	  		document.querySelector("#addressSelectManage").addEventListener("click",function(){
	  			$app.openWin('buyAddress');
	  		});
	  		//--添加地址回来刷新地址选择页面
			api.addEventListener({
				name: 'addressAdd_'
			},function(ret, err){
				self.init();
			});
			//--地址列表管理返回刷新
			api.addEventListener({
				name: 'addressList_'
			},function(ret, err){
				self.list = '';
				self.init();
			});

			function btnKeyBack(){
				var list = document.querySelectorAll("#addressList input");
				for(var i=0; i < list.length; i++){
					if(list[i].checked){
						var address_id = list[i].dataset.addressid;
			  			var index = list[i].dataset.index;
			  			var data = self.list[+index];
			  			self.address_id = address_id;
			  			//--返回提交订单页面
			  			api.sendEvent({
							name:'addressSelect_',
							extra:{
								address_id: address_id,
								address: data
							}
						});
						$api.setTimeout(function(){
							api.closeWin();
						},300);
						break;
					}
					if(i == list.length - 1){
						api.toast({
	                        msg: "请选择收货地址！",
	                        duration: 2000,
	                        location: 'middle'
	                    });
					}
				}
			}

			//--点击上面按钮返回
			$api.addEvt($api.dom('#btn-back-new'), 'click', function() {
	            btnKeyBack();
	        });

			//--返回键
			api.addEventListener({
				name: 'keyback'
			},function(ret, err){
				btnKeyBack();
			});

			//--右滑
	        api.addEventListener({
			    name:'swiperight'
			},function(ret,err){
			    btnKeyBack();
         	});

	  	},
	  	created: function(){
	  		this.address_id = api.pageParam.address_id;
	  		this.init();
	  	}
	};
	var even = function() {}
	var newVue = new Vue(vm);
	even();
	});
	}
